<template>
      <div class="serch">
          <div class="serch-header">
            <div class="out" @click="out"><van-icon name="arrow-left"/></div>
              <form class="serch-from">
                <van-icon name="search" class="icon"/><input type="text" placeholder="请输入您想要的物品" v-model="val"><van-icon name="cross" class="icon" @click="clear"/>
            </form>
             <div class="serch-btn" @click="search">搜索</div>
          </div>
          <div class="list">
          <dl v-for="(item, index) in list" :key="index">
            <dt><img :src="item.img" alt="" @click="detal(item.pid)"></dt>
            <dd>
              <h3>{{item.pname}}</h3>
              <p class="des">{{item.des}}</p>
              <span class="mode">{{item.mode}}</span>
              <p class="price">￥{{item.price}}</p>
              <div class="addcart">
                <van-icon name="shopping-cart-o" />
              </div>
            </dd>
          </dl>
         
        </div>
      
    </div>
</template>

<script>
import Vue from 'vue';
import { Icon } from 'vant';

Vue.use(Icon);
import { Search } from "@/api/home";
export default {
  data() {
    return {
      val:"",
      list:[]
    }
  },
  methods: {
    out(){
      this.$router.go(-1)
    },
    clear(){
      this.vel=null
    },
    async search(){
       const res = await Search(this.val);
      console.log(res);
      this.list = res.data.data;
    }
  },
}
</script>

<style lang="scss">
.serch{
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  .serch-header{
      width: 100%;
      height: .9rem;
     text-align: center;
      line-height: .9rem;
      background: #fff;
      display: flex;
      justify-content: center;
      align-items: center;
      .out{
        width: 15%;
        height: 100%;
        font-size: 25px;
         display: flex;
        align-items: center;
      }
      .serch-from{
        width: 70%;
        height: 100%;
        display: flex;
        align-items: center;
        background: #f7f8fa;
        border-radius: 50px;
        display: flex;
      justify-content: center;
      align-items: center;
      padding: 0 5px;
        .icon{
          display: flex;
          justify-content: center;
          align-items: center;
          font-size: 16px;
        }
        input{
          width: 100%;
          height: 100%;
          border:none;
          background: none;
          padding-left: 10px;
          display: flex;
          align-items: center;
        span{
          color: #999;
        }
        }
      }
      .serch-btn{
         width: 15%;
        height: 100%;
        font-size: 16px;
        display: flex;
        align-items: center;
        margin-left: 15px;
      }
  }
  .list{
      flex: 1;
      overflow: auto;
      dl{
        width:100%;
        height: 3rem;
        display: flex;
        margin-top: 10px;
        dt{
          width: 40%;
          height: 100%;
          margin-left: 10px;
          img{
            width: 100%;
            height: 100%;
          }
        }
        dd{
          width: 60%;
          height: 100%;
          padding: 10px;
          position: relative;
          .des{
            font-size: 12px;
            color: #9B9B9B;
            margin-top: 6px;
          }
          .mode{
            margin-top: 10px;
            width: 30px;
            height: 18px;
            display: block;
            background: orange;
            color: white;
            display: flex;
            justify-content: center;
            align-items: center;
            border-radius: 3px;
          }
          .price{
            font-size: 17px;
            color: red;
            font-weight:600;
            margin-top: 50px;
          }
          .addcart{
            width: 30px;
            height: 30px;
            background: red;

            position: absolute;
            bottom: 15px;
            right: 10px;
            color: white;
            font-size: 18px;
            border-radius: 50%;
            display: flex;
            justify-content: center;
            align-items: center;
          }
        }
      }
    }
}
</style>
